<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp"%>

<head>
    <title>注册</title>
    <meta name="heading" content="注册"/>
	<style>
		.content{
			float:left;width:900px;
			padding:10px;
		}

		.info{
			float:left;
			display: inline;
			margin:0px 0px 0px 250px;
		}
		.regInfo{
			margin:5px 0px 5px 0px;
			font-size:14px;		
		}
	</style>	
</head>
<body>
<script>
	function checkUsername(){
		var username = $('signup_user_username').value;
		var pattern = /^[a-zA-Z\d]+([\w\.\-]*[a-zA-Z\d]+)?$/;
		var pattern1 = /\s+/;
		var errorTip;
		var form = $('signup');
		
		if(username.length < 4 || username.length > 18){
			validation.clearErrorMessages(form);
			validation.clearErrorLabels(form);
			if(username.length < 4){
				errorTip = '用户名太短,';
			}else if(username.length > 18){
				errorTip = '用户名太长,';
			}
			errorTip += '用户名长度为4~18位';
			validation.addError($('signup_user_username'), errorTip);
			return;
		}
		if(!pattern.test(username)){
			validation.clearErrorMessages(form);
			validation.clearErrorLabels(form);
			if(pattern1.test(username)){
				errorTip = '用户名中不能包含空格';
			}else {
				errorTip = '用户名只能以字母、数字开头和结尾';
			}
			validation.addError($('signup_user_username'), errorTip);
			return;
		}
		var url = '<s:url value="/register/isUserExist.do"/>';
		jQuery.getJSON(url,{'user.username':username},
				function(dataFromServer){
					validation.clearErrorMessages(form);
					validation.clearErrorLabels(form);
					if(dataFromServer[4].isUsernameExist){
						validation.addError($('signup_user_username'), '该用户名已经存在，请使用其他用户名来注册.');
					}
				});
	}
	function checkOnSubmit(){
		var result1 = validateForm_signup();
		var result2 = true;
		if(!$('lisence').checked){
			var form = $('signup');
			validation.addError($('lisence'), '您必须同意《服务条款》才能注册.');
			result2 = false;
		}
		return result1 && result2;
	}
	setCookie('menuSelected', '/register/register-input.do');
</script>
<div class="content">
	<div class="info">
		<s:form id="signup" name="signupForm" namespace="/register" action="register" method="post" validate="true" onsubmit="return checkOnSubmit();">
			<s:hidden name="key"></s:hidden>
			<s:textfield key="user.username" cssClass="text medium" required="true" onchange="checkUsername()"/>
			<div style="width:230px;background:#F3F3F3 none repeat scroll 0 0;color:#666666;">
				<div>·登录名由字母a～z(不区分大小写)、数字0～9、点、减号或下划线组成</div>
				<div>·登录名只能以数字或字母开头和结尾，且长度为4～18位</div>
			</div>
			<s:textfield key="user.name" required="true" cssClass="text medium" inputcolspan="3"/>
			<s:password key="user.password" showPassword="true" required="true" 
		                    cssClass="text medium" inputcolspan="3"/>
		    <s:password key="user.confirmPassword" required="true" 
		                    showPassword="true" cssClass="text medium" inputcolspan="3"/>
			<s:textfield key="user.email" required="true" cssClass="text medium" inputcolspan="3"/>
			<td class="tdLabel"></td>
			<td>
				<table><tr><td>
					<s:checkbox id="lisence" name="lisence" theme="simple"/>
					我已看过并同意《<a href="<s:url value="#"/>" target="_blank">服务条款</a>》
				</td></tr></table>
			</td>
	        <s:submit key="button.register" cssClass="button" name=""/>
		</s:form>
	</div>
</div>

	
</body>